package com.example.qxfw.dzzh.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.CountryPoint;
import com.example.qxfw.common.entity.DisasterType;
import com.example.qxfw.common.entity.PotentialPoints;
import com.example.qxfw.common.entity.xt.DzjcRangeset;
import com.example.qxfw.common.entity.xt.DzjcTmset;
import com.example.qxfw.dzzh.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@Slf4j
@ApiIgnore
@Api(tags = "地质灾害-地质灾害灾点统计")
@RestController
@CrossOrigin
@RequestMapping("/zdtj")
public class ZdtjController {

    @Autowired
    private CountryPointService countryPointService;

    @Autowired
    private DisasterTypeService disasterTypeService;

    @Autowired
    private PotentialPointService potentialPointService;

    @Autowired
    private DzjcRangesetService dzjcRangesetService;

    @Autowired
    private DzjcTmsetService dzjcTmsetService;

    @ApiOperation("获取乡镇名字")
    @RequestMapping("/getCountryName")
    public SysResult getCountryName(){
        List<CountryPoint> list = countryPointService.list();
        return SysResult.success(list);
    }

    @ApiOperation("获取灾害类型")
    @RequestMapping("/getDisasterType")
    public SysResult getDisasterType(){
        List<DisasterType> list = disasterTypeService.list();
        return SysResult.success(list);
    }

    @ApiOperation("统计灾点")
    @RequestMapping("/getPotentialPoint")
    private SysResult getPotentialPoint(String country,String disType,String content){
        List<PotentialPoints> potentialPoints = potentialPointService.countByParams(country, disType, content);
        return SysResult.success(potentialPoints);
    }

    @ApiOperation("获取显示设置")
    @RequestMapping("/getRangeset")
    private SysResult getRangeset(){
        List<DzjcRangeset> list = dzjcRangesetService.list();
        return SysResult.success(list);
    }


    @ApiOperation("获取专题图设置")
    @RequestMapping("/getTmset")
    private SysResult getTmset(){
        List<DzjcTmset> list = dzjcTmsetService.list();
        return SysResult.success(list);
    }

    @ApiOperation("添加显示设置")
    @RequestMapping("/saveRangeset")
    private SysResult saveRangeset(@RequestBody DzjcRangeset dzjcRangeset){
        DzjcRangeset save = dzjcRangesetService.save(dzjcRangeset);
        return SysResult.success(save);
    }

    @ApiOperation("更新显示设置")
    @RequestMapping("/updateRangeset")
    private SysResult updateRangeset(@RequestBody DzjcRangeset dzjcRangeset){
        DzjcRangeset update = dzjcRangesetService.update(dzjcRangeset);
        return SysResult.success(update);
    }

    @ApiOperation("删除显示设置")
    @RequestMapping("/deleteRangeset")
    private SysResult deleteRangeset(Integer id){
        Integer rowId = dzjcRangesetService.deleteById(id);
        return SysResult.success(rowId);
    }

    @ApiOperation("添加专题图设置")
    @RequestMapping("/saveTmset")
    private SysResult saveTmset(@RequestBody DzjcTmset dzjcTmset){
        DzjcTmset save = dzjcTmsetService.save(dzjcTmset);
        return SysResult.success(save);
    }

    @ApiOperation("更新专题图设置")
    @RequestMapping("/updateTmset")
    private SysResult updateTmset(@RequestBody DzjcTmset dzjcTmset){
        DzjcTmset update = dzjcTmsetService.update(dzjcTmset);
        return SysResult.success(update);
    }

    @ApiOperation("删除专题图设置")
    @RequestMapping("/deleteTmset")
    private SysResult deleteTmset(Integer id){
        Integer rowId = dzjcTmsetService.deleteById(id);
        return SysResult.success(rowId);
    }
}
